home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 286_01 / chardisp.asm < prev    next >
Assembly Source File  |  1989-05-23  |  10KB  |  274 lines

  1.         TITLE   CHARDISP of GDS
  2.         page    60,132
  3.         .SFCOND
  4. ;
  5. ; *==========================================================*
  6. ; *                                                          *
  7. ; *   This file contains character display related functions *
  8. ; *     _wrtc -- move the pixel pattern from buffer to       *
  9. ; *              the current frame.                          *
  10. ; *     _copyfont -- copy the pixel data to buffer for       *
  11. ; *              manipulation.                               *
  12. ; *     _ctextL -- clip the left side of the pixel data      *
  13. ; *     _ctextR -- clip the right side of the pixel data     *
  14. ; *                                                          *
  15. ; *   See also the comment in writec function                *
  16. ; *                                                          *
  17. ; *==========================================================*
  18.  
  19. IFDEF   COLOR
  20.   IFDEF HERC
  21.    .err both display type defined
  22.   ENDIF
  23. else
  24.   IFNDEF HERC
  25.     HERC equ 0
  26.   ENDIF
  27. ENDIF
  28.  
  29. smo     equ     4       ; small model offset value
  30.  
  31. DGROUP  group   _DATA
  32. _DATA   segment word public 'DATA'
  33.         assume  ds:DGROUP
  34.         extrn   _LEFTWORD:word,_RIGHTWORD:word
  35.  
  36.         extrn   wrtvec:word
  37.  
  38. _DATA   ends
  39.  
  40. _TEXT   segment byte public 'CODE'
  41.         assume  cs:_TEXT,ds:DGROUP
  42.         extrn   $calc:near
  43.  
  44.         public  _wrtc,_copyfont,_ctextL,_ctextR
  45. ;
  46. ;  wrtc(x,y,shift,write_width,height,store_width,buffer,offset_flag);
  47. ;  x,y are the top-left-hand corner of the character box
  48. ;  shift -- the number of bits to shift right before writing
  49. ;  write_width -- the number of words per row in writing
  50. ;  store_width -- the number of words per row occupied in buffer
  51. ;  buffer -- address of the pixel data buffer
  52. ;  offset_flag -- 0 means normal, non-0 means skip first pixel word per row
  53. ;                 in the buffer. (see the comment below.
  54. _wrtc   proc    near    ; public to c
  55.         push    bp
  56.         mov     bp,sp
  57.         push    si
  58.         push    di
  59.         shl     word ptr [bp+smo+10],1  ; convert store_width to byte
  60.         mov     ax,[bp+smo+6]   ; load write_width into ax
  61.         shl     ax,1            ; convert to byte
  62.         sub     [bp+smo+10],ax  ; store_width now contains the difference
  63.                                 ; of store_width and write_width in byte
  64.         test    word ptr [bp+smo+4],08h ; shift >= 8 ?
  65.         jz      wc10                    ; no, jump
  66.         sub     word ptr [bp+smo+4],8   ; sub. shift by 8
  67.         mov     bx,[bp+smo+12]  ; then shift the pixel data by 1 byte
  68.         mov     di,[bp+smo+6]   ; write_width
  69.         mov     si,[bp+smo+8]   ; height
  70. wc11:   mov     cx,di
  71.         mov     al,0
  72. wc12:   mov     dx,[bx]
  73.         xchg    dh,dl
  74.         xchg    dh,al
  75.         mov     [bx],dx
  76.         inc     bx
  77.         inc     bx
  78.         loop    wc12            ; until the whole row is shifted
  79.         add     bx,[bp+smo+10]  ; move to begining of next row
  80.         dec     si              ; until every row is shifted
  81.         jnz     wc11
  82. wc10:   mov     ax,[bp+smo+4]
  83.         test    ax,ax
  84.         jz      short wc4
  85.         mov     si,[bp+smo+8]   ; height
  86.         mov     dx,[bp+smo+12]  ; buffer address
  87.         mov     di,ax
  88. wc1:    mov     bx,dx
  89. wc2:    mov     cx,[bp+smo+6]
  90.         clc
  91. wc3:    rcr     word ptr [bx],1
  92.         inc     bx
  93.         inc     bx
  94.         loop    wc3             ; until the whole row is shifted 1 bit
  95.         dec     di
  96.         jnz     short wc1       ; until the row is shifted n times
  97.         add     bx,[bp+smo+10]
  98.         mov     dx,bx
  99.         mov     di,ax
  100.         dec     si
  101.         jnz     short wc2       ; until every row is shifted
  102. wc4:    mov     si,[bp+smo+12]  ; pixel buffer address
  103. wc5:    mov     ax,[bp+smo]     ; x coordinate
  104.         mov     bx,[bp+smo+2]   ; y coordinate
  105.         call    $calc           ; calculate destination addr.
  106.         mov     es,ax
  107.         mov     cx,[bp+smo+6]   ; load write_width (in words)
  108.         test    [bp+smo+14],0ffffh ; flag set?
  109.         jz      wc6             ; no, skip to wc6
  110.         inc     si              ; otherwise skip first pixel word
  111.         inc     si
  112.         dec     cx              ; decrement write_width
  113.                                 ; in this case, write_width is at least 2
  114. wc6:    mov     ax,[si]
  115.         xchg    ah,al           ; xchg before writing
  116.         call    wrtvec
  117.         inc     si              ; move to next word
  118.         inc     si
  119.         inc     bx
  120.         inc     bx
  121.         loop    wc6             ; loop write_width times
  122.         add     si,[bp+smo+10]  ; move to begining of next row
  123.         inc     word ptr [bp+smo+2] ; move down one row (increment y)
  124.         dec     word ptr [bp+smo+8] ; decrement height
  125.         jnz     short wc5           ; if non-zero, loop
  126.         pop     di              ; else done
  127.         pop     si
  128.         pop     bp
  129.         ret
  130. _wrtc   endp
  131.  
  132. ;
  133. ;  copyfont(raw_data_width,height,store_width,raw_data_ptr,buffer);
  134. ;  raw_data_width -- number of byte per row
  135. ;  height -- in row
  136. ;  store_width -- number of words per row when stored in buffer
  137. ;  raw_data_ptr (huge) -- address of raw pixel data
  138. ;  buffer -- buffer address
  139. ;
  140. _copyfont proc   near    ; public to c
  141.         push    bp
  142.         mov     bp,sp
  143.         push    si
  144.         push    di
  145.         mov     ax,ds
  146.         mov     es,ax
  147.         mov     al,[bp+smo+2]   ; height
  148.         mov     bl,[bp+smo+4]   ; store_width
  149.         mul     bl              ; multiple to get memory required
  150.         mov     cx,ax           ; move result to cx
  151.         mov     di,[bp+smo+10]  ; buffer
  152.         cld
  153.         xor     ax,ax           ; clear buffer first
  154.         rep stosw
  155.         mov     si,[bp+smo]
  156.         mov     dx,[bp+smo+4]
  157.         shl     dx,1            ; convert to byte
  158.         sub     dx,si           ; difference of store_width and raw_data_width
  159.         mov     di,[bp+smo+10]
  160.         les     bx,[bp+smo+6]   ; get raw data pointer
  161. cf1:    mov     cx,si
  162. cf2:    mov     ax,es:[bx]
  163.         xchg    ah,al
  164.         dec     cx
  165.         jz      cf3             ; means raw_data_width is an odd number
  166.         mov     [di],ax
  167.         inc     bx
  168.         inc     di
  169.         inc     bx
  170.         inc     di
  171.         loop    short cf2
  172. cf4:    add     di,dx
  173.         dec     word ptr [bp+smo+2]
  174.         jnz     short cf1       ; move row by row
  175.         pop     di
  176.         pop     si
  177.         pop     bp
  178.         ret
  179. cf3:    xor     al,al           ; special handling of last byte if
  180.         mov     [di],ax         ; raw_data_width is odd
  181.         inc     bx
  182.         inc     di
  183.         jmp     short cf4
  184. _copyfont endp
  185. ;
  186. ;  ctextR(clip_start,store_width,height,buffer);
  187. ;  clip_start -- It is in number of bits from the left side of a row.
  188. ;                ctextR discards the bits after clip_start.
  189. ;  store_width -- width in word of each row
  190. ;  height -- 
  191. ;  buffer -- address of the buffer
  192. ;
  193. _ctextR proc    near    ; public to c
  194.         push    bp
  195.         mov     bp,sp
  196.         push    si
  197.         push    di
  198.         mov     bx,[bp+smo]     ; get clip_start
  199.         mov     si,bx
  200.         and     bx,0fh          ; clip_width mod 16
  201.         shl     bx,1
  202.         mov     ax,_RIGHTWORD[bx]       ; get mask to clear the right part
  203.         xchg    ah,al
  204.         mov     bx,[bp+smo+4]
  205.         mov     cl,4
  206.         shr     si,cl           ; last word need
  207.         mov     di,[bp+smo+6]   ; get buffer address
  208. cr1:    add     di,si
  209.         add     di,si           ; increase 2*si byte (si words)
  210.         and     [di],ax         ; clear bits after clip_start
  211.         inc     di              ; move to next word
  212.         inc     di
  213.         mov     cx,[bp+smo+2]
  214.         sub     cx,si
  215.         dec     cx              ; words left on the right of clip_start
  216.         jz      cr2             ; jump if none
  217.         mov     word ptr [di],0 ; else clear next word
  218.         shl     cx,1
  219.         add     di,cx
  220. cr2:    dec     bx
  221.         jnz     cr1             ; loop until every row is processed
  222.         pop